package com.baicaoyuan.web.common;

import com.baicaoyuan.web.enums.ClientTypeEnum;
import com.baicaoyuan.web.model.UserDO;
import com.baicaoyuan.web.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CheckPower {

    @Autowired
    UserService userService;

    public void checkPower(String token, Long userId) throws Exception {
        if (userService.checkToken(userId, token)) {
            UserDO userDO = userService.findOne(userId);
            if ("1".equals(userDO.getStatus()) && "3".equals(userDO.getWebAdmin())) {
            } else {
                throw new Exception("非管理员，无权限");
            }
        } else {
            throw new Exception("无权限");
        }
    }

    public void checkClient(String client) throws Exception {
        if (!ClientTypeEnum.ADMIN.getStatus().equals(client)) {
            throw new Exception("非管理员，无权限");
        }
    }
}
